package com.beverage.lemonade.process;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class UserInfoJson extends JSONObject {
	private SharedPreferences sp;
	private Context context;

	protected int PEIOD_LENGTH;
	protected int PERIOD_SPAN;
	protected int ISGRANTED;
	protected int CREATED_DATE;
	protected String USERNAME;
	protected String PASSWORD;
	protected String MARKER1;
	protected String MARKER2;
	protected String MARKER3;
	protected String MARKER4;
	protected String ID;

	public UserInfoJson(String json) throws JSONException {
		super(json);
		this.PEIOD_LENGTH = getInt(Constants.PERIOD_LENGTH);
		this.PERIOD_SPAN = getInt(Constants.PERIOD_SPAN);
		this.ISGRANTED = getInt(Constants.ISGRANTED);
		this.CREATED_DATE = getInt(Constants.CREATED_DATE);
		this.USERNAME = getString(Constants.USERNAME);
		this.PASSWORD = getString(Constants.PASSWORD);
		this.MARKER1 = getString(Constants.MARKER1);
		this.MARKER2 = getString(Constants.MARKER2);
		this.MARKER3 = getString(Constants.MARKER3);
		this.MARKER4 = getString(Constants.MARKER4);
		this.ID = getString(Constants.ID);

	}

	public UserInfoJson(Context context) throws JSONException {
		super();
		this.context = context;
		this.sp = PreferenceManager.getDefaultSharedPreferences(context);

		put(Constants.PERIOD_LENGTH, sp.getInt(Constants.PERIOD_LENGTH, 4));
		put(Constants.PERIOD_SPAN, sp.getInt(Constants.PERIOD_SPAN, 28));
		put(Constants.USERNAME, sp.getString(Constants.USERNAME, "USERNAME"));
		put(Constants.PASSWORD, sp.getString(Constants.PASSWORD, "PASSWORD"));
		put(Constants.ID, sp.getString(Constants.ID, "ID"));
		put(Constants.ISGRANTED, sp.getInt(Constants.ISGRANTED, 1));
		put(Constants.CREATED_DATE, sp.getInt(Constants.ISGRANTED, 1));
		put(Constants.MARKER1, sp.getString(Constants.MARKER1, "MARKER1"));
		put(Constants.MARKER2, sp.getString(Constants.MARKER2, "MARKER2"));
		put(Constants.MARKER3, sp.getString(Constants.MARKER3, "MARKER3"));
		put(Constants.MARKER4, sp.getString(Constants.MARKER4, "MARKER4"));

		this.PEIOD_LENGTH = getInt(Constants.PERIOD_LENGTH);
		this.PERIOD_SPAN = getInt(Constants.PERIOD_SPAN);
		this.ISGRANTED = getInt(Constants.ISGRANTED);
		this.USERNAME = getString(Constants.USERNAME);
		this.PASSWORD = getString(Constants.PASSWORD);
		this.MARKER1 = getString(Constants.MARKER1);
		this.MARKER2 = getString(Constants.MARKER2);
		this.MARKER3 = getString(Constants.MARKER3);
		this.MARKER4 = getString(Constants.MARKER4);
		this.ID = getString(Constants.ID);
	}

	public void setPeriodLength(int PERIOD_LENGTH) throws JSONException {
		this.PEIOD_LENGTH = PERIOD_LENGTH;
		put(Constants.PERIOD_LENGTH, String.valueOf(PERIOD_LENGTH));

	}

	public void setPeriodSpan(int PERIOD_SPAN) throws JSONException {
		this.PERIOD_SPAN = PERIOD_SPAN;
		put(Constants.PERIOD_SPAN, String.valueOf(PERIOD_SPAN));
	}

	public void setUsername(String USERNAME) throws JSONException {
		this.USERNAME = USERNAME;
		put(Constants.USERNAME, String.valueOf(USERNAME));
	}

	public void setCreatedDate(int CREATED_DATE) throws JSONException {
		this.CREATED_DATE = CREATED_DATE;
		put(Constants.CREATED_DATE, String.valueOf(CREATED_DATE));
	}

	public void setIsGranted(boolean ISGRANTED) throws JSONException {
		if (ISGRANTED) {
			this.ISGRANTED = 1;
			put(Constants.ISGRANTED, String.valueOf(1));
		} else {
			this.ISGRANTED = 0;
			put(Constants.ISGRANTED, String.valueOf(0));
		}

	}

	public void setPassword(String PASSWORD) throws JSONException {
		this.PASSWORD = PASSWORD;
		put(Constants.PASSWORD, PASSWORD);
	}

	public void setMARKER1(String MARKER1) throws JSONException {
		this.MARKER1 = MARKER1;
		put(Constants.MARKER1, MARKER1);
	}

	public void setMARKER2(String MARKER2) throws JSONException {
		this.MARKER2 = MARKER2;
		put(Constants.MARKER2, MARKER2);
	}

	public void setMARKER3(String MARKER3) throws JSONException {
		this.MARKER3 = MARKER3;
		put(Constants.MARKER3, MARKER3);
	}

	public void setMARKER4(String MARKER4) throws JSONException {
		this.MARKER4 = MARKER4;
		put(Constants.MARKER4, MARKER4);
	}

	public int getPEIOD_LENGTH() {
		return PEIOD_LENGTH;
	}

	public int getPERIOD_SPAN() {
		return PERIOD_SPAN;
	}

	public int getCREATED_DATE() {
		return PERIOD_SPAN;
	}

	public int getISGRANTED() {
		return ISGRANTED;
	}

	public String getUSERNAME() {
		return USERNAME;
	}

	public String getPASSWORD() {
		return PASSWORD;
	}

	public String getID() {
		return ID;
	}

	public String getMARKER1() {
		return MARKER1;
	}

	public String getMARKER2() {
		return MARKER2;
	}

	public String getMARKER3() {
		return MARKER3;
	}

	public String getMARKER4() {
		return MARKER4;
	}
}
